package p5;

import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: YKH
 * Date: 2023-11-29
 * Time: 20:43
 */

/**
 * 八皇后问题
 */
public class Main2 {
    static int n;
    static boolean []col = new boolean[20];
    static boolean []dj = new boolean[20];
    static boolean []fdj = new boolean[20];
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        char[][] map = new char[n+1][n+1];
        for(int i=1;i<=n;i++){
            for(int j=1;j<=n;j++){
                map[i][j] = '.';
            }
        }
        dfs(1, map);
    }

    private static void dfs(int u, char[][]map) {
        if(u == n+1){
            for(int i=1;i<=n;i++){
                for(int j=1;j<=n;j++){
                    System.out.print(map[i][j]);;
                }
                System.out.println();
            }
            System.out.println();
            return;
        }
        int x = u;
        for(int y=1;y<=n;y++){
            if(!col[y] && !dj[y-x+n] && !fdj[y+x]){
                map[x][y] = 'Q';
                col[y] = dj[y-x+n] = fdj[y+x] = true;
                dfs(u+1, map);
                map[x][y] = '.';
                col[y] = dj[y-x+n] = fdj[y+x] = false;
            }
        }
    }
}
